﻿// -----------------------------------------------------------------------
// <copyright file="HighriseClient.cs" company="Spardo, LLC">
// Copyright (c) 2011 SPardo, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Highrise
{
    using System;
    using DotNet37Signals.Client.Highrise.Contracts;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class HighriseClient : IDisposable
    {
        internal Credentials Credentials { get; private set; }

        public HighriseClient(Credentials credentials)
        {
            this.Credentials = credentials;
        }

        public T GetContract<T>() where T : class, IHighriseContract
        {
            return new RestClientBase<T>(this.Credentials, "highrisehq.com", true).GetContract();
        }

        #region IDisposable Members

        public void Dispose()
        {
            this._account = null;
            this._cases = null;
            this._categories = null;
            this._comments = null;
            this._companies = null;
            this._customFields = null;
            this._deals = null;
            this._emails = null;
            this._groups = null;
            this._memberships = null;
            this._notes = null;
            this._parties = null;
            this._people = null;
            this._tags = null;
            this._tasks = null;
            this._users = null;
        }

        #endregion

        private IAccountContract _account;
        public IAccountContract Account
        {
            get { return this._account ?? (this._account = this.GetContract<IAccountContract>()); }
        }

        private ICasesContract _cases;
        public ICasesContract Cases
        {
            get { return this._cases ?? (this._cases = this.GetContract<ICasesContract>()); }
        }

        private ICategoriesContract _categories;
        public ICategoriesContract Categories
        {
            get { return this._categories ?? (this._categories = this.GetContract<ICategoriesContract>()); }
        }

        private ICommentsContract _comments;
        public ICommentsContract Comments
        {
            get { return this._comments ?? (this._comments = this.GetContract<ICommentsContract>()); }
        }

        private ICompaniesContract _companies;
        public ICompaniesContract Companies
        {
            get { return this._companies ?? (this._companies = this.GetContract<ICompaniesContract>()); }
        }

        private ICustomFieldsContract _customFields;
        public ICustomFieldsContract CustomFields
        {
            get { return this._customFields ?? (this._customFields = this.GetContract<ICustomFieldsContract>()); }
        }

        private IDealsContract _deals;
        public IDealsContract Deals
        {
            get { return this._deals ?? (this._deals = this.GetContract<IDealsContract>()); }
        }

        private IEmailsContract _emails;
        public IEmailsContract Emails
        {
            get { return this._emails ?? (this._emails = this.GetContract<IEmailsContract>()); }
        }

        private IGroupsContract _groups;
        public IGroupsContract Groups
        {
            get { return this._groups ?? (this._groups = this.GetContract<IGroupsContract>()); }
        }

        private IMembershipsContract _memberships;
        public IMembershipsContract Memberships
        {
            get { return this._memberships ?? (this._memberships = this.GetContract<IMembershipsContract>()); }
        }

        private INotesContract _notes;
        public INotesContract Notes
        {
            get { return this._notes ?? (this._notes = this.GetContract<INotesContract>()); }
        }

        private IPartiesContract _parties;
        public IPartiesContract Parties
        {
            get { return this._parties ?? (this._parties = this.GetContract<IPartiesContract>()); }
        }

        private IPeopleContract _people;
        public IPeopleContract People
        {
            get { return this._people ?? (this._people = this.GetContract<IPeopleContract>()); }
        }

        private ITagsContract _tags;
        public ITagsContract Tags
        {
            get { return this._tags ?? (this._tags = this.GetContract<ITagsContract>()); }
        }

        private ITasksContract _tasks;
        public ITasksContract Tasks
        {
            get { return this._tasks ?? (this._tasks = this.GetContract<ITasksContract>()); }
        }

        private IUsersContract _users;
        public IUsersContract Users
        {
            get { return this._users ?? (this._users = this.GetContract<IUsersContract>()); }
        }
    }
}
